package com.heima.behavior.kafkaconsumer;

import com.alibaba.fastjson.JSON;
import com.heima.behavior.service.IApPariseService;
import com.heima.behavior.service.IApReadService;
import com.heima.common.constants.KafkaConstants;
import com.heima.model.behavior.dtos.LikesBehaviorDto;
import com.heima.model.behavior.dtos.ReadBehaviorDto;
import com.heima.model.behavior.pojos.ApParise;
import com.heima.model.behavior.pojos.ApRead;
import com.heima.model.wemedia.pojos.WmNews;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author fkn
 * @description
 * @since 2024/8/23
 */
@Component
public class BehaviorListener {

    @Resource
    private IApPariseService apPariseService;

    @Resource
    private IApReadService apReadService;

    @KafkaListener(topics = KafkaConstants.BEHAVIOR_LIKE)
    public void like(String dto){
        ApParise apParise = JSON.parseObject(dto, ApParise.class);
        apPariseService.like(apParise);
    }

    @KafkaListener(topics = KafkaConstants.BEHAVIOR_UNLIKE)
    public void unlike(String dto){
        ApParise apParise = JSON.parseObject(dto, ApParise.class);
        apPariseService.unlike(apParise);
    }

    @KafkaListener(topics = KafkaConstants.BEHAVIOR_READ)
    public void read(String dto){
        ApRead apRead = JSON.parseObject(dto, ApRead.class);
        apReadService.read(apRead);
    }
}
